/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package db.definitions;

/**
 *
 * @author abracadabuda
 */
public class TriggerDefinition extends AbstractDefinition {
    private String name;
    private String time;
    private String event;
    private String schema;
    private String table;
    private String target;
    private String procedure;
    
    public TriggerDefinition() {
        schema = AbstractDefinition.prefix;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public String getProcedure() {
        return procedure;
    }

    public void setProcedure(String procedure) {
        this.procedure = procedure;
    }
    
    /**
     * returns SQL code of trigger definition (CREATE TRIGGER...)
     * @return SQL code
     */
    public String getSQL() {
        String sql = "CREATE TRIGGER \"" + name + "\" ";
        sql += time + " " + event + "\n";
        sql += "ON \"" + schema + "\".\"" + table + "\" " + target + "\n"; 
        sql += "EXECUTE PROCEDURE " + procedure + ";\n";
        return sql.replaceAll("%%%", "\"" + prefix + "\"");
    }
}
